﻿/*** MikeWare Framework ************************************
* This class is part of product of MikeWare.Framework.
* 
* Author      : Mike Cheers
* Mail        : mikecheers@126.com
* Create Date : 2018/9/16
* Summary     : 
* 
* 
* Modified By : 
* Date        : 
* Mail        : 
* Comment     : 
**************************************************************/

namespace MikeWare.Components.MikeLoggor.Policies
{
    using System;
    using System.Collections.Generic;

    public abstract class RollingPolicy : Policy
    {
        public Settings Setting { get; set; }
        public virtual Boolean ShouldRolling(Listener listener) { throw new NotImplementedException(); }

        public RollingPolicy(Settings setting)
        {
            Setting = setting;
        }

        internal static IList<RollingPolicy> BuildRollingPolicies(IList<Settings> attributes)
        {
            if (null == attributes || 0 == attributes.Count) return null;

            var result = new List<RollingPolicy>();

            foreach (var attribute in attributes)
            {
                switch (attribute.Name.Trim().ToUpper())
                {
                    case "TIMEBASEDTRIGGERINGPOLICY":
                        result.Add(new TimeBasedTriggeringPolicy(attribute));
                        break;
                    case "FILESIZETRIGGERINGPOLICY":
                        result.Add(new FileSizeTriggeringPolicy(attribute));
                        break;
                    case "RECORDSTRIGGERINGPOLICY":
                        result.Add(new RecordsTriggeringPolicy(attribute));
                        break;
                    default:
                        break;
                }
            }

            return result;
        }
    }
}
